package org.activemonitoring.monitors;

import org.activemonitoring.datastore.dao.DataStoreDao;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.assertEquals;

public class AopMethodMonitorCase {

    @Test
    public void testMonitorMethod() throws Exception {
        // setup
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
                "applicationContext-harvesters.xml", "applicationContext-datastore.xml",
                "applicationContext-test-aop.xml" });
        applicationContext.start();
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            System.out.println(beanName);
        }
        DataStoreDao dataStoreDao = applicationContext.getBean("dataStoreDao", DataStoreDao.class);
        // test
        IBusinessService monitoredService = applicationContext.getBean("monitoredService", IBusinessService.class);
        monitoredService.execute();
        Thread.sleep(1000L);
        // verify
        assertEquals(1, dataStoreDao.getMeasures().size());
        dataStoreDao.clear();
        applicationContext.stop();
    }
}
